package com.demo.servlet.entity;

public class Response {
    public final static int CODE_SUCCESS = 1;
    public final static int CODE_FAILED = 0;
    public final static int CODE_NOTLOGIN = -1;
    public final static String MESSAGE_SUCCESS_DEFAULT = "";
    public final static String MESSAGE_FAILED_DEFAULT = "";
    public final static String MESSAGE_NOTLOGIN_DEFAULT = "";


    private int code;
    private String message;
    private Object body;

    public final static Response success() {
        return success(null, MESSAGE_SUCCESS_DEFAULT);
    }

    public final static Response success(Object body) {
        return success(body, MESSAGE_SUCCESS_DEFAULT);
    }

    public final static Response success(Object body, String message){
        Response response = new Response();
        response.setCode(CODE_SUCCESS);
        response.setMessage(message);
        response.setBody(body);
        return response;
    }

    public final static Response failed(){
        return failed(MESSAGE_FAILED_DEFAULT);
    }

    public final static Response failed(String message){
        Response response = new Response();
        response.setCode(CODE_FAILED);
        response.setMessage(message);
        return response;
    }

    public final static Response noLogin(){
        Response response = new Response();
        response.setCode(CODE_NOTLOGIN);
        response.setMessage(MESSAGE_NOTLOGIN_DEFAULT);
        return response;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getBody() {
        return body;
    }

    public void setBody(Object body) {
        this.body = body;
    }
}
